package com.dotools.utils;

import android.graphics.drawable.Drawable;

import com.dotools.base.CommonConstants;
import com.dotools.debug.LOG;

public class RUtils {

    public static int getDrawableIdentifier(String name) {
        int indentify = Utilities.getApplicationContext().getResources().getIdentifier(name, "drawable", Utilities.sMainProcessName);
        if(CommonConstants.IS_DEBUG) {
            LOG.logI("name:"+name+",id:"+indentify);
        }
        if (indentify > 0) {
            return indentify;
        } else {
            return -1;
        }
    }

    public static int getStringIdentifier(String name) {
        int indentify = Utilities.getApplicationContext().getResources().getIdentifier(name, "string", Utilities.sMainProcessName);
        if(CommonConstants.IS_DEBUG) {
            LOG.logI("name:"+name+",id:"+indentify+" getString:"+Utilities.getApplicationContext().getString(indentify));
        }
        if (indentify > 0) {
            return indentify;
        } else {
            return -1;
        }
    }

    public static int getLayoutIdentifier(String name) {
        int indentify = Utilities.getApplicationContext().getResources().getIdentifier(name, "layout", Utilities.sMainProcessName);
        if(CommonConstants.IS_DEBUG) {
            LOG.logI("name:"+name+",id:"+indentify+" getlayout:"+Utilities.getApplicationContext().getString(indentify));
        }
        if (indentify > 0) {
            return indentify;
        } else {
            return -1;
        }
    }

    public static String getStringByIdentifier(String name) {
        int resId = getStringIdentifier(name);
        if(resId > 0) {
           try {
            return Utilities.getApplicationContext().getString(resId);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        }
        return null;
    }
    

    public static Drawable getDrawableByIdentifier(String name) {
        int resId = getDrawableIdentifier(name);
        if(resId > 0) {
           try {
            return Utilities.getApplicationContext().getResources().getDrawable(resId);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        }
        return null;
    }
}
